package com.ruoyi.web.controller.dangerControl;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.ruoyi.dangerControl.dto.LocationDto;
import com.ruoyi.dangerControl.dto.SysDepartDto;
import com.ruoyi.dangerControl.vo.SysDepartVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dangerControl.domain.SysDepart;
import com.ruoyi.dangerControl.service.ISysDepartService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 组织机构Controller
 *
 * @author lth
 * @date 2023-12-14
 */
@RestController
@RequestMapping("/dangerControl/depart")
public class SysDepartController extends BaseController
{
    @Autowired
    private ISysDepartService sysDepartService;

    /**
     * 查询组织机构列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:depart:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDepart sysDepart)
    {
        startPage();
        List<SysDepart> list = sysDepartService.selectSysDepartList(sysDepart);
        return getDataTable(list);
    }

    /**
     * 导出组织机构列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:depart:export')")
    @Log(title = "组织机构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDepart sysDepart)
    {
        List<SysDepart> list = sysDepartService.selectSysDepartList(sysDepart);
        ExcelUtil<SysDepart> util = new ExcelUtil<SysDepart>(SysDepart.class);
        util.exportExcel(response, list, "组织机构数据");
    }

    /**
     * 获取组织机构详细信息
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:depart:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(sysDepartService.selectSysDepartById(id));
    }

    /**
     * 新增组织机构
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:depart:add')")
    @Log(title = "组织机构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDepart sysDepart)
    {
        return toAjax(sysDepartService.insertSysDepart(sysDepart));
    }

    /**
     * 修改组织机构
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:depart:edit')")
    @Log(title = "组织机构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDepart sysDepart)
    {
        return toAjax(sysDepartService.updateSysDepart(sysDepart));
    }

    /**
     * 删除组织机构
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:depart:remove')")
    @Log(title = "组织机构", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysDepartService.deleteSysDepartByIds(ids));
    }


    /**
     * 查询组织树列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:depart:query')")
    @GetMapping("/getDepartList")
    public AjaxResult getDepartList()
    {
        SysDepartDto sysDepartDto = sysDepartService.getDepartList();
        return success(sysDepartDto);
    }



    /**
     * 通过部门ID查询部门内人员列表
     *
     */
//    @PreAuthorize("@ss.hasPermi('dangerControl:depart:query')")
//    @GetMapping("/getDepartPersonList")
//    public TableDataInfo getDepartPersonList(@RequestBody SysDepartVo vo){
//        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
//        List<SysDepart> list = sysDepartService.getDepartPersonList(vo);
//        return getDataTable(list);
//    }




}
